# -*- coding: utf-8 -*-

def index():
    return dict(
        )

def sip_config():
    config_name = 'sip'
    sip_config = ['appkey', 'secret', 'url', 'v']
    query = (db.config.name == config_name)

    form = db().select(db.config.ALL)
#    config = db(query).select('appkey', 'v', 'secret', 'url')
    config = db(query).select()
    config = config[0]

    response.flash = request.vars.flash

    return dict(
        form = SQLTABLE(form),
        config = config
        )

def interface():
    each_api = [i.api for i in db().select(db.interface.ALL)]
    form = FORM(TABLE(
        TR("API:",SELECT(each_api, _name='api', requires=IS_IN_SET(each_api))),
        TR("",INPUT(_type="submit",_value="SUBMIT")),
        ))
    if form.accepts(request.vars,session):
        response.flash="form accepted"
    elif form.errors:
        response.flash="form is invalid"

    try:
        api_name = form.vars.api
    except:
        api_name = None
    table = db(db.interface.api==api_name).select()

    return dict(
        table = table,
        each_api = each_api,
        form = form,
        )

